package tv.youxing.android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import tv.youxing.android.R;
import tv.youxing.android.custom.RoundRectImageView;
import tv.youxing.android.entity.AlbumInfoModel;
import tv.youxing.android.utils.PicassoUtils;

/**
 * Created by apple on 2017/4/22.
 */

/**
 * 项目名：   youxing
 * 包名：     tv.youxing.android .adapter
 * 文件名：   AlbumRecommendAdapter
 * 创建者：   叶克武
 * 创建时间： 2017/4/22 下午2:21
 * 描述：    TODO
 */
public class AlbumRecommendAdapter extends BaseAdapter {

    private Context context;
    private List<AlbumInfoModel.ResultBean.RecommedAlbumsBean> albumlist = new ArrayList<>();
    private LayoutInflater layoutInflater;

    public AlbumRecommendAdapter(Context context, List<AlbumInfoModel.ResultBean.RecommedAlbumsBean> albumlist) {
        this.context = context;
        this.albumlist = albumlist;
        this.layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return albumlist.size();
    }

    @Override
    public Object getItem(int position) {
        return albumlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (viewHolder==null){
            viewHolder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.layout_item_album_recommend, null);
            viewHolder.ivIcon = (RoundRectImageView) convertView.findViewById(R.id.ivIcon);
            viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle);
            viewHolder.tvDesc = (TextView) convertView.findViewById(R.id.tvDesc);
            viewHolder.tvCount = (TextView) convertView.findViewById(R.id.tvCount);
            viewHolder.tvEpisode = (TextView) convertView.findViewById(R.id.tvEpisode);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        AlbumInfoModel.ResultBean.RecommedAlbumsBean model = albumlist.get(position);
        PicassoUtils.loadImageView(context, model.getCover(),viewHolder.ivIcon);
        viewHolder.tvTitle.setText(model.getName());
        viewHolder.tvDesc.setText(model.getTeacher_job_title());
        viewHolder.tvCount.setText(model.getPlay_count() + "次");
        viewHolder.tvEpisode.setText(model.getMultimedia_count()+"集");

        return convertView;
    }

    class ViewHolder{
        private RoundRectImageView ivIcon;
        private TextView tvTitle;
        private TextView tvDesc;
        private TextView tvCount;
        private TextView tvEpisode;
    }

}
